package com.zqt.zqt805.controller;

import com.zqt.zqt805.domain.Product;
import com.zqt.zqt805.service.ProductService;
import com.zqt.zqt805.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "产品管理接口---张淇童0805")
@RestController
@RequestMapping("/api/products")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation(value = "添加产品", notes = "添加新产品")
    @PostMapping
    public AjaxResult addProduct(@RequestBody Product product) {
        productService.addProduct(product);
        return AjaxResult.success("Product added successfully");
    }

    @ApiOperation(value = "获取所有产品", notes = "获取所有产品信息")
    @GetMapping
    public AjaxResult getAllProducts() {
        return AjaxResult.success(productService.getAllProducts());
    }

    @ApiOperation(value = "更新产品", notes = "更新产品信息")
    @PutMapping("/upproject")
    public AjaxResult updateProduct( @RequestBody Product product) {
        productService.updateProduct(product);
        return AjaxResult.success("Product updated successfully");
    }

    @ApiOperation(value = "删除产品", notes = "删除指定产品")
    @DeleteMapping("/{product_id}")
    public AjaxResult deleteProduct(@ApiParam(value = "产品ID", required = true) @PathVariable int product_id) {
        productService.deleteProduct(product_id);
        return AjaxResult.success("Product deleted successfully");
    }
}